package com.totoro.tymapping.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author TOTORO
 * @date 2024/8/29 14:39
 */
public class ListUtil {

    /**
     * 集合按照指定个数分一组，返回List类型集合
     * @param originalList 原集合
     * @return 返回集合
     */
    public static <T> List<List<T>> splitList(List<T> originalList, Integer count) {
        List<List<T>> splitList = new ArrayList<>();
        int size = originalList.size();
        if(count > size) count = size;
        for (int i = 0; i < size; i += count) {
            int toIndex = Math.min(i + count, size);
            List<T> subList = originalList.subList(i, toIndex);
            splitList.add(subList);
        }
        return splitList;
    }

    public static <T> Boolean isNotBlank(List<T> list) {
        return null != list && !list.isEmpty();
    }
}
